package ds.tree;

public class TreeSize {

	private static int NODE_COUNT=0;
	
	/**
	 * Class to represent a tree.
	 *
	 * @author sivravis
	 *
	 */
	
	private static class TreeNode{
		int value;
		TreeNode left = null;
		TreeNode right = null;
		
		TreeNode(int val){
			this.value = val;
		}
		
		public String toString(){
			return String.valueOf(value);
		}
	}
		
	/**
	 * size of using recursion
	 * 
	 * @param args
	 */
	public static int size(TreeNode node){
		if(node == null){
			return 0;
		}
		return size(node.left)+1 + size(node.right);
	}

	private static TreeNode tree(){
		TreeNode A = new TreeNode(1);
		TreeNode B = new TreeNode(2);
		TreeNode C = new TreeNode(3);
		TreeNode D = new TreeNode(4);
		TreeNode E = new TreeNode(5);
		
		A.left = B;
		A.right = C;
		B.left = D;
		B.right = E;
		
		return A;
	}	
	public static void main(String[] args) {
		System.out.println("Size of Tree = " + size(tree()));
	}

}
